<?
require("../../common/init.php");
require("author.php");

$gee=$configuration; // gee, 意为赶车时候喊的"驾", 此处用来表示次页面的主角对象
$title=ROOT_VIEW_CONFIGURATION;
$url='configuration';
$do=isset($_GET["do"])?clean($_GET["do"]):'view'; // 操作: 查看/编辑/删除
$action=isset($_POST["action"])?clean($_POST["action"]):''; // 数据库操作: CURD

$id=1; if (isset($_GET["id"])) $id = @$_GET["id"];
$is_super_user=is_super_user($userid);

switch ($action){
	case "update":sql_update(); break;
}

$where=array();
if(!$is_super_user) {
	$where[]=array('name'=>'is_enabled','val'=>1);
	$where[]=array('name'=>'module','val'=>'site','opn'=>'=','start'=>'(');
	$where[]=array('name'=>'module','val'=>'seo','opn'=>'=','and'=>'or');
	$where[]=array('name'=>'module','val'=>'point','opn'=>'=','and'=>'or');
	$where[]=array('name'=>'module','val'=>'email','opn'=>'=','and'=>'or','end'=>')');
	$rows=$configuration->get_rows_advanced(1024,$where,'id','asc');
}
else {
	$where[]=array('name'=>'module','val'=>'aboutus','opn'=>'<>');
	$where[]=array('name'=>'module','val'=>'contactus','opn'=>'<>');
	$where[]=array('name'=>'module','val'=>'search','opn'=>'<>');
	$where[]=array('name'=>'module','val'=>'logo','opn'=>'<>');
	$rows=$configuration->get_rows_advanced(1024,$where,'seq_no');
}

function update($info)
{
	global $url;
	echo '<form method="post" action="'.$url.'.php">';
  	show_box($info, true);
	echo '<input type="hidden" name="action" value="update">';
	echo '</form>';
}
function show_info($info)
{
	global $url;
	show_box($info, false);
}
function sql_update()
{
	global $gee,$url,$is_super_user;
	//print_r($_POST);
	$data=$_POST;
	unset($data['action']);
	$ok=0;
	foreach($data as $key=>$val){
		$prefix=substr($key,0,2);
		if($prefix=='id'){
			$id=substr($key,3);
			$arr=array(
				'value'=>$val,
			);
			// 启用/关闭
			if($is_super_user){
				$tem_check=0;
				$name_check='check_'.$id;
				if(isset($_POST[$name_check])) {
					$tem_check=$_POST[$name_check];
					$arr['is_enabled']=$tem_check;
				}
				else $arr['is_enabled']=0;
			}
			$arr['id']=$id;
			//pre($arr);
			if($gee->update($arr, 'id', $id ) ) $ok=1;
		}
	}
	//if($ok) yell(ROOT_UPDATE_SUCCESS,$url.".php");
}

// view 加载视图
require ROOTVIEW.'configuration.php';
